﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using DAL;
using Utility;
namespace BUS
{
    public class Tbl_sanpham_BUS
    {
        public static Tbl_sanpham_Collection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            Tbl_sanpham_DAL spDAL = new Tbl_sanpham_DAL();
            return spDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static Tbl_sanpham_Collection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            Tbl_sanpham_DAL spDAL = new Tbl_sanpham_DAL();
            return spDAL.Get(cri.Criter, 0, 0, Tbl_sanpham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static Tbl_sanpham_Entities GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_sanpham_Columns.STT.ToString(), Condition.EQUAL, iD);
            Tbl_sanpham_DAL spDAL = new Tbl_sanpham_DAL();
            Tbl_sanpham_Collection spCollection = spDAL.Get(cri.Criter, 0, 0, Tbl_sanpham_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (spCollection.Count > 0)
                return spCollection[0];
            return null;
        }

        public static int Insert(Tbl_sanpham_Entities sp)
        {
            Tbl_sanpham_DAL spDAL = new Tbl_sanpham_DAL();
           return spDAL.insert(sp);
        }
        public static void Update(Tbl_sanpham_Entities sp)
        {
            Tbl_sanpham_DAL spDAL = new Tbl_sanpham_DAL();
            spDAL.Update(sp);
        }
        public static void Delete(int id)
        {
            Tbl_sanpham_DAL spDAL = new Tbl_sanpham_DAL();
            spDAL.Delete(id);
        }
    }
}
